package com.xiaxueqi.web.shop;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.niagara.dao.Page;
import com.niagara.service.base.BaseService;
import com.xiaxueqi.entity.book.AppFavorite;
import com.xiaxueqi.entity.book.BookForsaleExt;
import com.xiaxueqi.entity.book.BookSelled;
import com.xiaxueqi.entity.security.AppUserExt;

public class ShopHomeAction {

	@Autowired
	private BaseService baseService;
	private Page<BookForsaleExt> bookForsaleList;// 展现自己店铺在卖的书籍
	private List<BookSelled> bookSelledList;
	private List<AppFavorite> favoriteBooks;
	private List<AppFavorite> friends;
	private AppUserExt user;
	private Integer id;

	// type="redirect" type="dispatcher"
	// @Action(value = "/shop/*/home", results = { @Result(name = "success",
	// location = "../shop-home.jsp", type = "dispatcher") })
	@SuppressWarnings("unchecked")
	public String execute() {
		user = this.baseService.get(AppUserExt.class, id);
		Map map = new HashMap();
		map.put("ownerId", id);
		this.bookForsaleList = this.baseService.findForPaging(
				BookForsaleExt.class, map, 1, 10);

		map = new HashMap();
		map.put("salerId", id);
		map.put("start", 0);
		map.put("pageSize", 6);
		map.put("orderByClause", "create_time desc");
		this.bookSelledList = this.baseService.find(BookSelled.class, map,
				"select_paging");

		map = new HashMap();
		map.put("ownerId", id);
		map.put("favoriteType", "book");
		map.put("start", 0);
		map.put("pageSize", 5);
		map.put("orderByClause", "create_time desc");
		this.favoriteBooks = this.baseService.find(AppFavorite.class, map,
				"select_paging");

		map = new HashMap();
		map.put("ownerId", id);
		map.put("favoriteType", "user");
		map.put("start", 0);
		map.put("pageSize", 5);
		map.put("orderByClause", "create_time desc");
		this.friends = this.baseService.find(AppFavorite.class, map,
				"select_paging");

		return "success";
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Page<BookForsaleExt> getBookForsaleList() {
		return bookForsaleList;
	}

	public Integer getId() {
		return id;
	}

	public AppUserExt getUser() {
		return user;
	}

	public void setUser(AppUserExt user) {
		this.user = user;
	}

	public List<BookSelled> getBookSelledList() {
		return bookSelledList;
	}

	public List<AppFavorite> getFavoriteBooks() {
		return favoriteBooks;
	}

	public List<AppFavorite> getFriends() {
		return friends;
	}

}
